{% extends 'base.html' %}
{% block content %}
    <!-- Main content -->
    <div class="content">

        <div class="row">
            <!-- /.col -->
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#" data-toggle="tab" aria-expanded="true">系统设置</a></li>
                    </ul>
                    <div class="tab-content">

                        <div class="tab-pane active" id="defaultForm">
                            {% for msg in get_flashed_messages(category_filter=["ok"]) %}
                                <div class="alert alert-success alert-dismissible">
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×
                                    </button>
                                    <h4><i class="icon fa fa-check"></i> 操作成功！</h4>
                                    {{ msg }}
                                </div>
                            {% endfor %}
                            <form class="form-horizontal" method="post">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">{{ form.weburl.label }}</label>
                                    <div class="col-sm-10">
                                        {{ form.weburl }}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail"
                                           class="col-sm-2 control-label">{{ form.webname.label }}</label>
                                    <div class="col-sm-10">
                                        {{ form.webname }}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">{{ form.record.label }}</label>
                                    <div class="col-sm-10">
                                        {{ form.record }}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">{{ form.describe.label }}</label>
                                    <div class="col-sm-10">
                                        {{ form.describe }}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">{{ form.keywords.label }}</label>
                                    <div class="col-sm-10">
                                        {{ form.keywords }}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        {{ form.csrf_token }}
                                        {{ form.submit }}
                                        {{ form.rollbak }}
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- /.tab-pane -->
                    </div>
                    <!-- /.tab-content -->
                </div>
                <!-- /.nav-tabs-custom -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->

    </div>
    <!-- /.content -->

{% endblock content %}
{% block footer %}
<script>
    $(function () {
        $("#myDiv").click(function () {
            // 验证表单未输入或者状态不通过是不允许提交
{#            $('#defaultForm').bootstrapValidator('validate');#}
{#            if (!$('#defaultForm').data('bootstrapValidator').isValid()) return;#}

            // 获取表单的字段和值并返回Json格式
            var datalin = {};
            $('#defaultForm input[name]').each(function () {
                datalin[this.getAttribute('name')] = this.value;
            });
            var data = {data: JSON.stringify(datalin)}
            console.log(JSON.stringify(data));
            $('#defaultForm').serializeArray()
            // 通过ajax方式提交数据
            $.ajax({
                url: '{{ url_for('admin.adduser') }}',
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (res) {
                    $('#exampleModal').modal('hide')
                    swal(res.result, "", "success")
                    console.log(0)
                },
                error: function (res) {
                    $('#exampleModal').modal('hide')
                    swal("失败", "", "error")
                    console.log(1)
                }

            })
        })
    });
</script>
{% endblock footer %}